<!--
 * @Author: 梁青春
 * @Date: 2025-10-16 15:36:35
 * @LastEditTime: 2025-10-16 16:07:05
 * @LastEditors: 梁青春
-->
<template>
  <div class="right-panel">
    <div class="title">
      <span>收费信息</span>
    </div>

    <!-- 缴费信息卡片 -->
    <div class="payment-info-card">
      <div class="info-section">
        <div class="info-row">
          <span class="label">完成时间</span>
          <span class="value">{{ paymentInfo.completionTime }}</span>
        </div>
        <div class="info-row">
          <span class="label">收费员</span>
          <span class="value">{{ paymentInfo.cashier }}</span>
        </div>
        <div class="info-row">
          <span class="label">计费总额</span>
          <span class="value amount">{{ formatAmount(paymentInfo.totalAmount) }}</span>
        </div>
        <div class="info-row">
          <span class="label">预缴押金</span>
          <span class="value amount">{{ formatAmount(paymentInfo.deposit) }}</span>
        </div>
        <div class="info-row">
          <span class="label">结算方式</span>
          <span class="value">{{ paymentInfo.paymentMethod }}</span>
        </div>
      </div>

      <!-- 发票状态 -->
      <div class="invoice-status">
        <div class="info-row">
          <span class="label">发票状态</span>
          <span class="value status-pending">{{ paymentInfo.invoiceStatus }}</span>
        </div>
      </div>

      <!-- 结算流水切换按钮 -->
      <div class="settlement-toggle" @click="toggleSettlementFlow">
        <span class="toggle-label">结算流水</span>
        <el-icon class="toggle-icon" :class="{ expanded: isSettlementExpanded }">
          <ArrowDown />
        </el-icon>
      </div>

      <!-- 结算流水内容 -->
      <transition name="slide-down">
        <div v-if="isSettlementExpanded" class="settlement-flow">
          <div v-for="(record, index) in settlementRecords" :key="index" class="flow-record">
            <div class="record-type" :class="record.type === '收' ? 'income' : 'refund'">
              {{ record.type }}
            </div>
            <div class="record-amount">{{ formatAmount(record.amount) }}</div>
            <div class="record-details">
              <div class="record-info">
                <span class="operator">{{ record.operator }}</span>
                <span class="time">{{ record.time }}</span>
                <span class="method">{{ record.method }}</span>
              </div>
            </div>
          </div>
        </div>
      </transition>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ArrowDown } from '@element-plus/icons-vue'

// 响应式数据
const isSettlementExpanded = ref(false)

// 缴费信息数据
const paymentInfo = reactive({
  completionTime: '2025-05-14 16:50',
  cashier: '陆林轩',
  totalAmount: 600.0,
  deposit: 1000.0,
  paymentMethod: '现金',
  invoiceStatus: '待开发票'
})

// 结算流水记录
const settlementRecords = reactive([
  {
    type: '收',
    amount: 1000.0,
    operator: '毛不易',
    time: '2023-05-17 14:40',
    method: '微信'
  },
  {
    type: '收',
    amount: 200.0,
    operator: '蔡小龙',
    time: '2023-05-17 14:40',
    method: '现金'
  }
])

// 切换结算流水显示状态
const toggleSettlementFlow = () => {
  isSettlementExpanded.value = !isSettlementExpanded.value
}

// 格式化金额显示
const formatAmount = amount => {
  return `¥${amount.toFixed(2)}`
}
</script>

<style scoped lang="scss">
@use '@/assets/styles/variables.module.scss' as *;

.right-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  .title {
    height: $sub-navbar-height;
    line-height: $sub-navbar-height;
    font-size: $font-size;
    border-bottom: 1px solid $border-color;
    text-align: center;
  }
}

.payment-info-card {
  background: #ffffff;
  overflow: hidden;

  .info-section {
    padding: 0 $padding-lg;
    border-bottom: 1px solid $border-color;
  }

  .info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: $padding-md;
    &:last-child {
      padding-bottom: $padding-md;
    }
    .label {
      color: #606266;
      font-size: $font-size-sm;
      min-width: 80px;
    }

    .value {
      color: #303133;
      font-size: $font-size-sm;
      font-weight: 500;

      &.amount {
        color: $blue;
        font-weight: 600;
        font-size: $font-size-sm;
      }

      &.status-pending {
        color: $yellow;
        font-weight: 600;
      }
    }
  }

  .invoice-status {
    padding: 0 $padding-lg;
    background-color: #fafbfc;
    border-bottom: 1px solid $border-color;
  }

  .settlement-toggle {
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.3s ease;
    background-color: #fafbfc;

    &:hover {
      background-color: #f0f2f5;
    }

    .toggle-label {
      color: #303133;
      font-size: 14px;
      font-weight: 500;
    }

    .toggle-icon {
      color: $blue;
      transition: transform 0.3s ease;

      &.expanded {
        transform: rotate(180deg);
      }
    }
  }

  .settlement-flow {
    border-top: 1px solid #f0f2f5;
    background-color: #fafbfc;

    .flow-record {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      padding: 12px 20px;
      border-bottom: 1px solid #f0f2f5;

      &:last-child {
        border-bottom: none;
      }

      .record-type {
        width: 32px;
        height: 24px;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: 600;
        margin-right: 12px;

        &.income {
          background-color: #e7f5ff;
          color: $blue;
        }

        &.refund {
          background-color: #fff2e8;
          color: $yellow;
        }
      }

      .record-details {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .record-amount {
          color: #303133;
          font-size: 15px;
          font-weight: 600;
        }

        .record-info {
          display: flex;
          align-items: center;
          gap: 12px;
          font-size: 13px;
          color: #606266;

          .operator {
            font-weight: 500;
          }

          .time {
            color: #909399;
          }

          .method {
            color: $blue;
            font-weight: 500;
          }
        }
      }
    }
  }
}

// 展开收起动画
.slide-down-enter-active,
.slide-down-leave-active {
  transition: all 0.3s ease;
  max-height: 200px;
  overflow: hidden;
}

.slide-down-enter-from,
.slide-down-leave-to {
  max-height: 0;
  opacity: 0;
}

// 响应式布局
@media (max-width: 768px) {
  .right-panel {
    padding: 16px;
  }

  .payment-info-card {
    .info-section,
    .invoice-status,
    .settlement-toggle {
      padding: 12px 16px;
    }

    .info-row {
      flex-direction: column;
      align-items: flex-start;
      gap: 4px;

      .label {
        min-width: auto;
        font-size: 13px;
      }

      .value {
        font-size: 14px;

        &.amount {
          font-size: 16px;
        }
      }
    }

    .settlement-flow {
      .flow-record {
        padding: 10px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;

        .record-details {
          width: 100%;
          flex-direction: column;
          align-items: flex-start;
          gap: 4px;

          .record-info {
            gap: 8px;
            flex-wrap: wrap;
          }
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .right-panel {
    padding: 12px;

    .title {
      font-size: 15px;
      margin-bottom: 16px;
    }
  }

  .payment-info-card {
    .settlement-flow {
      .flow-record {
        .record-info {
          font-size: 12px;
        }
      }
    }
  }
}
</style>
